package com.znf.biz.system.controller;

import com.znf.base.PageRespDto;
import com.znf.base.Result;
import com.znf.biz.system.dto.sys.req.*;
import com.znf.biz.system.dto.sys.resp.SysUserRespDto;
import com.znf.biz.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author Xiewm
 * @since 2024-11-06
 */

@Slf4j
@Data
@RestController
@Api(tags = "用户接口")
@RequestMapping("/sysUser")
public class SysUserController {

    private final ISysUserService sysUserService;


    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result<PageRespDto<SysUserRespDto>> page(@RequestBody SysUserPageReqDto param) {
        PageRespDto<SysUserRespDto> data = sysUserService.page(param);
        return Result.success(data);
    }


    @ApiOperation("查询")
    @GetMapping("/get")
    public Result<SysUserRespDto> get(@RequestParam Long userId) {
        SysUserRespDto data = sysUserService.get(userId);
        return Result.success(data);
    }

    @ApiOperation("新增用户")
    @PostMapping("/add")
    public Result<Void> add(@RequestBody SysUserAddReqDto param) {
        sysUserService.add(param);
        return Result.success();
    }

    @ApiOperation("修改用户")
    @PostMapping("/modify")
    public Result<Void> modify(@RequestBody SysUserModifyReqDto param) {
        sysUserService.modify(param);
        return Result.success();
    }


    @ApiOperation("修改密码")
    @PostMapping("/changePwd")
    public Result<Void> changePwd(@Validated @RequestBody ChangePwdReqDto param) {
        sysUserService.changePwd(param);
        return Result.success();
    }

    @ApiOperation("重置密码")
    @PostMapping("/resetPwd")
    public Result<Void> resetPwd(@Validated @RequestBody ResetPwdReqDto param) {
        sysUserService.resetPwd(param);
        return Result.success();
    }

}
